Repository navigation
Add missing Program and Project Methods - #64988
Isabel Duan (iisaduan) wants to merge 17 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The filesystem check incorrectly excludes in-program supplemental files without physical files, causing containsFile to return false even when getSourceFile succeeds.
1 open issue
What changed in this PR
Adds missing Program and Project methods to the JavaScript API, backed by native compiler and project services.
Changes:
- Exposes program statistics, checker access, file lists, option diagnostics, and resolved project references.
- Adds project membership, root-file, and configuration-file queries.
- Updates protocol definitions and generated synchronous APIs, with behavioral and generator-parity tests.
| File | Description |
|---|---|
tsc/internal/project/projectcollection.go |
Checks editor- and API-open files. |
tsc/internal/compiler/program.go |
Collects filtered option diagnostics. |
tsc/internal/checker/types.go |
Defines relation-cache statistics. |
tsc/internal/checker/exports.go |
Exposes relation-cache entry counts. |
tsc/internal/api/session.go |
Implements new API request handlers. |
tsc/internal/api/session_program_test.go |
Tests membership, statistics, and checker reuse. |
tsc/internal/api/proto.go |
Defines new requests and response types. |
packages/typescript/test/sync/api.test.ts |
Adds generated synchronous API tests. |
packages/typescript/test/sync/api-generators.test.ts |
Checks generator parity for new methods. |
packages/typescript/test/async/api.test.ts |
Tests new methods and edge cases. |
packages/typescript/src/api/sync/api.ts |
Adds generated synchronous and generator methods. |
packages/typescript/src/api/proto.generated.ts |
Updates generated protocol declarations. |
packages/typescript/src/api/async/api.ts |
Implements asynchronous Program and Project methods. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Concurrent cold-cache calls can return inconsistent project-reference object identities, while sequential per-file requests prevent automatic batching and add a round trip for each file.
2 open issues
1 resolved since last review
Review effort: Balanced
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
In addition to the inline comments, let's remove
program.getSourceFiles()—not a good idea for anyone to do this pre-filtering; we'll think about an explicitly filtered and/or streaming batch API in the futureprogram.getTypeChecker()—that's not the ownership model anymore, and there's no reason to make an API request for it- all of the
Projectmethods; they can all be done more directly offProgramandParsedCommandLineso I don't want to expand that API surface unnecessarily.
|
removed |

Missing
ProgramAPI methods: https://github.com/microsoft/TypeScript/pull/64749/changes#diff-4776036ff539c2fa009621dc13a9f2c8fd15d50e9302e8a361614ab640659a2eR117getIdentifierCount()- Total parsed identifiers across the program’s source files.getInstantiationCount()- Number of type-instantiation operations performed by the API checker.getNodeCount()- Total syntax-tree nodes across the program’s source files.getOptionsDiagnostics()- Sorted, deduplicated compiler-option and configuration-related program diagnostics. Excludes source-file and config-parsing diagnostics.getProjectReferences()- Direct project references declared for the program, or undefined when absent.getRelationCacheSizes()- Current entry counts in the checker’s assignable , identity , subtype , and strictSubtype caches.getResolvedProjectReferences()- Resolved reference graph, including parsed configurations, config source files, and nested references. Preserves shared/circular references and missing entries.getRootFileNames()- Root file names supplied when creating the program or obtained from its configuration—not imported dependencies.getSourceFiles()- All loaded source files, including dependencies and libraries, in program order. Reuses cached source-file objects.getSymbolCount()- Binder-created symbols across source files plus symbols allocated by the API checker.getTypeChecker()- Initializes the server-side API checker if necessary and returns the project’s existingCheckerobject.getTypeCount()- Number of types allocated by the API checker.ProjectAPI Methods:containsFilegetFileNamesgetRootFileshasRoots,isRoothasConfigFilegetSourceFile